﻿namespace Snipps.Services
{
    using System.Threading;
    using System.Windows;

    using Snipps.Core.Entities;

    using Clipboard = System.Windows.Clipboard;
    using TextDataFormat = System.Windows.TextDataFormat;
    using System.Windows.Forms;

    public class ClipboardExportImportSnippetService : IExportImportSnippetService
    {
        private readonly IWindowOperationsService _windowOperationsService;

        public ClipboardExportImportSnippetService(IWindowOperationsService windowOperationsService)
        {
            _windowOperationsService = windowOperationsService;
        }

        public void Export(Snippet snippetOld)
        {
            Clipboard.SetText(snippetOld.Content);
            _windowOperationsService.HideWindow();
            Thread.Sleep(100);
            SendKeys.SendWait("^v");
        }

        public Snippet Import()
        {
            var snippet = new Snippet { Content = Clipboard.GetText(TextDataFormat.Text) };

            return snippet;
        }
    }
}